package com.sdk.bigdata.model;

import com.alibaba.fastjson.annotation.JSONField;
import com.sdk.bigdata.exceptions.DataException;

import java.util.HashMap;
import java.util.Map;

// 物品
public class Item extends BaseModel {

    @JSONField(name = "item_id")
    private String itemId;

    @JSONField(name = "item_type")
    private String itemType;

    private String name;
    private Double price;

    public Item(String type, String itemId, String itemType, String name, Double price, Map<String, Object> properties) {
        super(type, properties);
        this.itemId = itemId;
        this.itemType = itemType;
        this.name = name;
        this.price = price;
    }

    public Item() {
    }

    public String getItemId() {
        return itemId;
    }

    public void setItemId(String itemId) {
        this.itemId = itemId;
    }

    public String getItemType() {
        return itemType;
    }

    public void setItemType(String itemType) {
        this.itemType = itemType;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Double getPrice() {
        return price;
    }

    public void setPrice(Double price) {
        this.price = price;
    }

    @Override
    public void validAttribute() {
        if (null == this.getType() || (!this.getType().equals("item_set") && !this.getType().equals("item_delete"))) {
            throw new DataException("property [Type] is not item_set or item_delete");
        }
        this.setTime(System.currentTimeMillis());
        // check uid
        if (null == this.getItemId() || this.getItemId().equals("")) {
            throw new DataException("property [ItemId] can't be empty");
        }
        if (this.getItemId().length() > 255) {
            throw new DataException("the max length of property [ItemId] is 255");
        }
        if (null == this.getProperties()) {
            this.setProperties(new HashMap<>());
        }
    }
}
